package com.dxb.test.thread;

/**
 * ClassName：com.dxb.test.thread.JoinABC <br>
 * Description：join实现多个线程顺序执行 <br>
 *
 * @author 戴晓波 <br>
 * Date 2022/2/14/014 10:11 <br>
 * @version v1.0 <br>
 */
public class JoinABC implements Runnable {
    private Thread thread;
    private String name;

    public JoinABC(Thread thread, String name) {
        this.thread = thread;
        this.name = name;
    }

    @Override
    public void run() {
        if (thread != null) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(name);
    }

    public static void main(String[] args) {
        Thread a = new Thread(new JoinABC(null, "A"));
        Thread b = new Thread(new JoinABC(a, "B"));
        Thread c = new Thread(new JoinABC(b, "C"));
        a.start();
        b.start();
        c.start();
    }
}
